<template>
  <div class="app-container">
    <SearchForm
      v-show="showSearch"
      v-model="queryParams"
      :options="options.formOps"
      @onQuery="getList"
    >
    </SearchForm>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd"
          >新增</el-button
        >
      </el-col> -->

      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <Table
      ref="table"
      :auto-featch="true"
      :fetch-data="fetchData"
      :options="options.table"
      actionWidth="160"
    >
      <template #actionButton="{ row }">
        <el-button type="text" icon="Edit" @click="handleFiles(row)"
          >附件</el-button
        >
        <el-button type="text" icon="Edit" @click="handleEdit(row)"
          >查看</el-button
        >
      </template></Table
    >
    <DialogVform
      :formJson="formJson"
      ref="dialogVform"
      @onSubmit="onSubmit"
      :showButton="false"
    ></DialogVform>

    <FileDialog
      title="文件"
      ref="fileDialog"
      :limit="10000"
      @onSubmit="onFileSubmit"
      :showButton="false"
    ></FileDialog>
  </div>
</template>

<script setup>
import Table from "@/components/Table/index.vue";
import SearchForm from "@/components/searchForm/index";
import DialogVform from "@/components/dialogVform/index";
import { apis as APIS } from "@/api/aqsc/aqgz.js";
import formJson from "./components/options.json";
import { useAsyncData, useFormJson } from "@/views/hooks/useAsyncData.js";
import FileDialog from "@/components/filesDialog";

const { proxy } = getCurrentInstance();
const ops = useFormJson(formJson, {
  sort: [],
  sortable: [],
});
const options = reactive({
  table: ops,
  formOps: ops.filter((i) =>
    ["docType", "docNumber", "docName"].includes(i.prop)
  ),
});
const showSearch = ref(true);
const dialogVform = ref();
const table = ref();

const {
  onSubmit,
  fetchData,
  handleAdd,
  handleEdit,
  getList,
  handleDel,
  queryParams,
} = useAsyncData({
  APIS,
  formJson,
  dialogVform,
  table,
  proxy,
  filterForm: {
    isEnable: 0,
  },
});

// 附件
const fileDialog = ref();
const selectRow = ref({});
const handleFiles = (row) => {
  selectRow.value = row;
  fileDialog.value.open(row.rulesRegulationsFileList);
};
</script>

<style lang="scss" scoped></style>
